package program.utils;

import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.TextAlignment;
import program.domain.Memory;
import java.util.ArrayList;

/**
 * @program: OSAlgorithms
 * @description: GUI工具
 * @author: Echo-dev
 * @create: 2021-11-06 16:40
 **/
public class ViewUtil {

    private static ArrayList<Color> colors = new ArrayList<>();

    private static double heightSum;

    private static double heightSumL;


    public static double getHeightSum() {
        return heightSum;
    }

    public static void setHeightSum(double heightSum) {
        ViewUtil.heightSum = heightSum;
    }

    public static double getHeightSumL() {
        return heightSumL;
    }

    public static void setHeightSumL(double heightSumL) {
        ViewUtil.heightSumL = heightSumL;
    }

    static {
        colors.add(Color.PINK);
        colors.add(Color.CHOCOLATE);
        colors.add(Color.PURPLE);
        colors.add(Color.TOMATO);
        colors.add(Color.SLATEBLUE);
        colors.add(Color.LAWNGREEN);
        colors.add(Color.NAVY);
        colors.add(Color.ROSYBROWN);
        colors.add(Color.CORNSILK);
        colors.add(Color.MAROON);
        colors.add(Color.DARKORANGE);
        colors.add(Color.CYAN);
        colors.add(Color.THISTLE);
    }

    public static Circle createCircle(){
        Circle circle = new Circle();
        circle.setCenterX(100);
        circle.setCenterY(100);
        circle.setVisible(true);
        circle.setRadius(50);
        circle.setStroke(Color.BLACK);
        circle.setFill(Color.WHITE);
        return circle;
    }

    public static Rectangle createRectangle(Memory memory,int maxHeight){
        double height = 800*(MathUtil.getPercent(memory.getLength(),maxHeight));
        double translateY = 800*(MathUtil.getPercent(memory.getStart(),maxHeight));
        Rectangle rectangle = new Rectangle();
        rectangle.setHeight(height);
        rectangle.setWidth(600);
        rectangle.setFill(Color.CRIMSON);
        rectangle.setTranslateY(translateY-heightSum);
        heightSum += height;
        return rectangle;
    }

    public static Label createAdrLabel(Memory memory, int maxHeight){
        double height = 800*(MathUtil.getPercent(memory.getLength(),maxHeight));
        double translateY = 800*(MathUtil.getPercent(memory.getStart(),maxHeight));
        Label label = new Label();
        label.setMinHeight(height);
        label.setMinWidth(100);
        label.setAlignment(Pos.TOP_LEFT);
        label.setText(String.valueOf(memory.getStart()));
        label.setTranslateY(translateY-heightSumL);
        heightSumL += height;
        return label;
    }

    public static void setColor(Circle circle){
        if (!colors.isEmpty()){
            circle.setFill(colors.get(0));
            colors.remove(0);
        }
    }

}
